# -*- coding: utf8 -*-
"""Wx to/from X11"""

import X11_keysimdef as keysimdef
from X11_keysimdef import *
# 'from wx import *' takes too much time
import wx

# synonim list -- first element is WX code, second - X11
_synonims = [
     (wx.WXK_BACK, XK_BackSpace),
     (wx.WXK_NUMPAD_PAGEUP, XK_KP_Page_Up),
     (wx.WXK_NUMPAD_PAGEDOWN, XK_KP_Page_Down),
     (wx.WXK_SPACE, XK_space),
     (wx.WXK_ALT, XK_Alt_L),  # I was unable to find differencee between left and right alt in WX
     (wx.WXK_SHIFT, XK_Shift_L), # same stands for SHIFT
     (wx.WXK_CONTROL, XK_Control_R), # and control
#    (wx.WXK_?, XK_?),
]

_synonims.extend(map(lambda (_char, _code): (ord(_char), _code), (
     (")", XK_parenright),
     ("!", XK_exclam),
     ("@", XK_at),
     ("#", XK_numbersign),
     ("$", XK_dollar),
     ("%", XK_percent),
     ("^", XK_caret),
     ("&", XK_ampersand),
     ("*", XK_asterisk),
     ("(", XK_parenleft),
     ("-", XK_minus),
     ("=", XK_equal),
     ("+", XK_plus),
     ("_", XK_underscore),
     ("[", XK_bracketleft),
     ("]", XK_bracketright),
     (";", XK_semicolon),
     (":", XK_colon),
     ("'", XK_apostrophe),
     ('"', XK_quotedbl),
     (",", XK_comma),
     ("<", XK_less),
     (".", XK_period),
     (">", XK_greater),
     ("/", XK_slash),
     ("?", XK_question),
     ("\\", XK_backslash),
     ("|", XK_brokenbar),
     ("{", XK_braceleft),
     ("}", XK_braceright),
)))

# add F-keys (yes, I'm lazy)
for _id in range(1, 25):
    _synonims.append((
        getattr(wx, "WXK_F%i" % _id),
        getattr(keysimdef, "XK_F%i" % _id),
    ))

# add latin keys (yes, I am very lazy)
for _code in range(ord("a"), ord("z")+1):
    for _key in (chr(_code), chr(_code).upper()):
        _synonims.append((
            # wx states that it uses ASCII codes here
            ord(_key),
            getattr(keysimdef, "XK_%s" % _key),
        ))

for _code in range(ord("0"), ord("9")+1):
        _key = chr(_code)
        _synonims.append((
            # wx states that it uses ASCII codes here
            _code,
            getattr(keysimdef, "XK_%s" % _key),
        ))
        _synonims.append((
            getattr(wx, "WXK_NUMPAD%s" % _key),
            getattr(keysimdef, "XK_KP_%s" % _key),
        ))

# fill in numpad (in non- numLock mode) relation
for _name in ("Space", "Tab", "Enter", "F1", "F2", "F3", "F4", "Home", "Left",
    "Up", "Right", "Down", "Prior", "Next", "End" , "Begin", "Insert",
    "Delete", "Equal", "Multiply", "Add", "Separator", "Subtract", "Decimal",
    "Divide"):
    _synonims.append((
            getattr(wx, "WXK_NUMPAD_%s" % _name.upper()),
            getattr(keysimdef, "XK_KP_%s" % _name.title()),
    ))

# fill in similar-named generic values
for _name in ("Escape", "Delete", "left", "right", "up", "down",
    "insert", "home", "delete", "end", "tab", "return"):
    _synonims.append((
            getattr(wx, "WXK_%s" % _name.upper()),
            getattr(keysimdef, "XK_%s" % _name.title()),
    ))

# -----------------------------
# _synonims list must be filled by now
# -----------------------------

_wxToX11 = dict(_synonims)
_x11ToWx = dict((_x11, _wx) for (_wx, _x11) in _synonims)

def toX11(key):
    return _wxToX11[key]

def toWx(key):
    return _x11ToWx[key]

# vim: set sts=4 sw=4 et :
